package com.qianfeng.iot.sdk.job;

//
//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖镇楼                  BUG辟易  
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  
//  


import com.dc3.common.constant.CommonConstant;
import com.dc3.common.model.DriverEvent;
import com.qianfeng.iot.sdk.bean.driver.DriverContext;
import com.qianfeng.iot.sdk.service.DriverService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Created by Jackiechan on 2022/8/2 9:16
 *
 * @author Jackiechan
 * @version 1.0
 * @since 1.0
 */
@Component
public class DriverStatusScheduleJob extends QuartzJobBean {

    public DriverStatusScheduleJob() {
    }

    @Value("${spring.application.name}")
    private String serviceName;


    private DriverService driverService;


    @Autowired
    public void setDriverService(DriverService driverService) {
        this.driverService = driverService;
    }


    private DriverContext driverContext;

    @Autowired
    public void setDriverContext(DriverContext driverContext) {
        this.driverContext = driverContext;
    }

    /**
     * 定时任务要执行的操作
     * @param context
     * @throws JobExecutionException
     */
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        System.err.println("开始发送心跳了");
        //发送心跳
        driverService.driverEventSender(new DriverEvent(serviceName, CommonConstant.Driver.Event.DRIVER_HEARTBEAT,driverContext.getDriverStatus(),20, TimeUnit.SECONDS));
    }
}
